package cmd

import (
	"fsd/api"
	"encoding/json"
	"fmt"
	"github.com/spf13/cobra"
	"net/http"
)

var allGameCmd = &cobra.Command{
	Use:   "allgame",
	Short: "print all game id",
	Long:  "print all game id",
	Run:   allGame,
}

func init() {
	rootCmd.AddCommand(allGameCmd)
}

func allGame(cmd *cobra.Command, args []string) {
	resp, err := http.Get("http://" + cfgData.Api.LAddr + "/allgame")
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer resp.Body.Close()
	retJson := new(api.AllGameAck)
	json.NewDecoder(resp.Body).Decode(retJson)
	fmt.Printf("%+v \n", retJson)
}
